package jmine.tec.sync.domain;

import java.sql.Blob;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Constraint;
import jmine.tec.sync.domain.enumx.SynchronizationOperationType;

import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.authorization.annotation.DisplayName;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;
import bancosys.tec.persist.hibernate.type.StaticIdEnumType;

/**
 * @author gabriel.silva
 */
@Entity
@Alias("SYNCER")
@Table(name = "SYNCHRONIZATION_ERROR")
@SequenceGenerator(name = "SEQ_SYNCER", sequenceName = "SEQ_SYNCER")
@Documentation("ARMAZENA INFORMACOES DA ENTIDADE, QUE DEVIDO A UM ERRO DE SINCRONIZACAO, NAO PODE SER SALVA NO SISTEMA")
public class SynchronizationErrorEntity extends PersistableBusinessObject {

    public static final int MAX_SOURCE_SIZE = 32;

    private Long id;

    private Long remoteEntityId;

    private String entityClass;

    private String message;

    private String source;

    private String entityNaturalKey;

    private SynchronizationOperationType operationType;

    private Blob entity;

    /**
     * @return Long
     */
    @Id
    @Column(name = "COD_ERRO_SYNC")
    @Documentation("CODIGO DE IDENTIFICACAO DO ERRO")
    @GeneratedValue(generator = "SEQ_SYNCER")
    public Long getId() {
        return this.id;
    }

    /**
     * @return Long
     */
    @Column(name = "REMOTE_ID", nullable = false)
    @Documentation("ARMAZENA O ID ORIGINAL DA ENTIDADE NO SISTEMA DE ORIGEM")
    public Long getRemoteEntityId() {
        return this.remoteEntityId;
    }

    /**
     * @return {@link String}
     */
    @Column(name = "ENTITY_CLASS", nullable = false)
    @Documentation("ARMAZENA A CLASSE DA ENTIDADE NO SISTEMA DE ORIGEM")
    public String getEntityClass() {
        return this.entityClass;
    }

    /**
     * {@inheritDoc}
     */
    @Column(name = "MESSAGE", length = 10485760)
    @Type(type = "org.hibernate.type.TextType")
    @Documentation("MENSAGEM DO ERRO DE SINCRONIZACAO")
    public String getMessage() {
        return this.message;
    }

    /**
     * @return o tipo desse comando. Pode ser uma das contantes INSERT/UPDATE ou DELETE
     */
    @Column(name = "TP_OPERATION", precision = 1)
    @DisplayName(value = "Evento", order = "1")
    @Documentation("INDICA A OPERACAO REALIZADA NO SISTEMA DE ORIGEM: INCLUSAO/ALTERACAO  (0), EXCLUSAO (1)")
    @Type(type = "bancosys.tec.persist.hibernate.type.StaticIdEnumType", parameters = @Parameter(name = StaticIdEnumType.ENUM_CLASS, value = "jmine.tec.sync.domain.enumx.SynchronizationOperationType"))
    @Constraint(suffix = "JT_0")
    public SynchronizationOperationType getOperationType() {
        return this.operationType;
    }

    /**
     * @return ca entidade serializada.
     */
    @Basic(fetch = FetchType.LAZY)
    @Type(type = "bancosys.tec.persist.hibernate.type.UpdatableBlobType")
    @Column(name = "ENTITY", nullable = true)
    @Documentation("ARMAZENA A REPRESENTACAO SERIALIZADA DA ENTIDADE QUE NAO PODE SER SALVA NO SISTEMA")
    public Blob getEntity() {
        return this.entity;
    }

    /**
     * @return {@link String}
     */
    @Column(name = "SOURCE", length = MAX_SOURCE_SIZE)
    @Documentation("ARMAZENA O NOME DO SISTEMA DE ORIGEM DA ENTIDADE")
    public String getSource() {
        return this.source;
    }

    /**
     * @return the nameEntity
     */
    @Column(name = "ENTITY_NATURAL_KEY", nullable = true)
    @Documentation("ARMAZENA A NATURAL KEY DA ENTIDADE SINCRONIZADA")
    public String getEntityName() {
        return this.entityNaturalKey;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param remoteEntityId the remoteEntityId to set
     */
    public void setRemoteEntityId(Long remoteEntityId) {
        this.remoteEntityId = remoteEntityId;
    }

    /**
     * @param entityClass the entityClass to set
     */
    public void setEntityClass(String entityClass) {
        this.entityClass = entityClass;
    }

    /**
     * @param message the message to set
     */
    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * @param source the source to set
     */
    public void setSource(String source) {
        this.source = source;
    }

    /**
     * @param typeOperation the typeOperation to set
     */
    public void setOperationType(SynchronizationOperationType typeOperation) {
        this.operationType = typeOperation;
    }

    /**
     * @param entity the entity to set
     */
    public void setEntity(Blob entity) {
        this.entity = entity;
    }

    /**
     * @param nameEntity the nameEntity to set
     */
    public void setEntityName(String nameEntity) {
        this.entityNaturalKey = nameEntity;
    }

}
